local ma__maojian = fk.CreateSkill {
  name = "ma__maojian",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["ma__maojian"] = "冒谏",
  [":ma__maojian"] = "锁定技，当你使用手牌后，若此牌未造成伤害，你令上一张牌的唯一目标横置（若已横置则改为令你摸一张牌）。",

  ["$ma__maojian1"] = "",
  ["$ma__maojian2"] = "",
}

ma__maojian:addEffect(fk.CardUseFinished, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player == target and player:hasSkill(ma__maojian.name) and data:isUsingHandcard(player) and not data.damageDealt then
      local to
      player.room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
        if e.id < player.room.logic:getCurrentEvent().id then
          if e.data:isOnlyTarget(e.data.tos[1]) and not e.data.tos[1].dead  then
          to = e.data.tos[1]
          end
          return true
        end
      end, 0)
      if to then
        event:setCostData(self, {tos = {to}})
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local last_tos = event:getCostData(self).tos[1]
    if last_tos.chained then
      player:drawCards(1, ma__maojian.name)
    else last_tos:setChainState(true)
    end
  end,
})

return ma__maojian
